import Page
from Page import Service
from Base.Base import Base
from selenium.webdriver.common.by import By


class ServiceCityPage(Base):
    """
    城市选择
    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 左侧的home键
        self.city_home_btn = (By.XPATH, Service.RESOURCE_ID.format("ivHome"))

        # 左侧的返回键
        self.city_back_btn = (By.XPATH, Service.RESOURCE_ID.format('ivBack'))

        # GPS定位标题
        self.city_gps_title_text = (By.XPATH, Page.TEXT.format("GPS定位"))

        # 定位图标
        self.city_positioning_icon = (By.XPATH, Service.RESOURCE_ID.format("location_img"))

        # 定位城市名称
        self.city_positioning_name_text = (By.XPATH, Service.RESOURCE_ID.format("location_tv"))

        # 手动选择标题
        self.city_manual_selection_title_text = (By.XPATH, Page.TEXT.format("手动选择"))

        # 城市首字母分类
        self.city_list_initials_text = (By.XPATH, Service.store_list_city_category_one_text.format(""))

        # 城市首字母城市
        self.city_list_initials_first_city_text = (By.XPATH, Service.store_list_city_category_one_name_text.format(""))

        # 城市列表名称(非首字母)
        self.city_list_city_two_name_text = (By.XPATH, Service.store_list_city_category_two_name_text.format(""))

        # 城市字母表
        self.city_letter_list_sidebar_img = (By.XPATH, Service.RESOURCE_ID.format("sideBar"))

        # 城市滑动条
        self.city_slide_img = (By.XPATH, Service.RESOURCE_ID.format("xmscrollbar"))

    def click_home(self):
        """
        点击左侧的home键

        :return:None
        """
        self.click_element(self.city_home_btn)

    def click_back(self):
        """
        点击左侧的back键

        :return:None
        """
        self.click_element(self.city_back_btn)

    def get_gps_title(self):
        """
        获取gps标题

        :return:获取元素
        """
        return self.find_element_o(self.get_gps_title())

    def get_positioning(self):
        """
        获取城市图标

        :return:获取元素
        """
        return self.find_element_o(self.city_positioning_icon)

    def get_positioning_name(self):
        """
        获取城市名称

        :return:获取元素
        """
        return self.find_element_o(self.city_positioning_name_text)

    def get_manual_selection_title(self):
        """
        获取手动选择标题

        :return:获取元素
        """
        return self.find_element_o(self.city_manual_selection_title_text)

    def get_list_initials(self, index=1):
        """
        获取城市列表分类

        index默认为1
        :return:获取元素
        """
        self.city_list_initials_text = (By.XPATH, Service.store_list_city_category_one_text.format(index))
        return self.find_element_o(self.city_list_initials_text)

    def get_list_initials_first_city(self, index=1):
        """
        获取城市列表第一个分类城市名称

        index默认为1
        :return:获取元素
        """
        self.city_list_initials_first_city_text = (
            By.XPATH, Service.store_list_city_category_one_name_text.format(index))
        return self.find_element_o(self.city_list_initials_first_city_text)

    def click_list_initials_first_city(self, index=1):
        """
        点击城市列表第一个分类城市名称

        index默认为1
        :return:获取元素
        """
        self.city_list_initials_first_city_text = (
            By.XPATH, Service.store_list_city_category_one_name_text.format(index))
        self.click_element(self.city_list_initials_first_city_text)

    def get_list_city_two_name(self, index=None, city_name=None):
        """
        获取城市列表第二个分类城市名称

        index默认为'鞍山市'
        :return:获取元素
        """
        if index is None:
            self.city_list_city_two_name_text = (By.XPATH, Page.TEXT.format(city_name))
        else:
            self.city_list_city_two_name_text = (By.XPATH, Service.store_list_city_category_two_name_text.format(index))
        return self.find_element_o(self.city_list_city_two_name_text)

    def click_list_city_two_name(self, index=None, city_name=None):
        """
        点击城市列表第二个分类城市名称

        index默认为2
        city_name默认为'鞍山市'
        :return:点击元素
        """
        if index is None:
            self.city_list_city_two_name_text = (By.XPATH, Page.TEXT.format(city_name))
        else:
            self.city_list_city_two_name_text = (By.XPATH, Service.store_list_city_category_two_name_text.format(index))
        self.click_element(self.city_list_city_two_name_text)

    def get_letter_list_sidebar(self):
        """
        获取城市字母表

        :return:获取元素
        """
        return self.find_element_o(self.city_letter_list_sidebar_img)

    def get_slide(self):
        """
        获取滑动条

        :return:获取元素
        """
        return self.find_element_o(self.city_slide_img)

    def swipe_city_name(self, direction='up'):
        """
        滑动城市名称

        :return:获取元素
        """
        self.swipe_o(location=(560, 560, 409, 509), direction=direction)

    def is_display_service_city(self):
        """
        是否进入城市列表选择

        :return: bool
        """
        return self.is_display(self.city_gps_title_text)
